package top.liujingyanghui.crypto.mybatisplus.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import top.liujingyanghui.crypto.mybatis.annotation.CryptoKey;
import top.liujingyanghui.crypto.mybatis.annotation.CryptoString;
import top.liujingyanghui.crypto.mybatis.annotation.CryptoStrings;
import top.liujingyanghui.crypto.mybatis.enums.CryptoMode;
import top.liujingyanghui.crypto.mybatisplus.entity.User;
import top.liujingyanghui.crypto.mybatisplus.param.UserParam;
import top.liujingyanghui.crypto.mybatisplus.rule.PhoneCryptoRule;

import java.util.List;
import java.util.Map;

/**
 * @author : wdh
 * @since : 2022/5/23 16:31
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    @CryptoKey(key = "phone", rule = PhoneCryptoRule.class)
    List<Map<String, Object>> selectByMapperMap(Map<String, String> param);

    // 如果是实体入参加密或者是响应解密需要在实体中加注解
    List<User> selectByEntity(@Param("user") User user);

    // 如果是实体入参加密或者是响应解密需要在实体中加注解
    Page<User> selectByEntity(@Param("page") Page<User> page, @Param("user") User user);

    User selectOneByEntity(User user);

    // 入参为单个List<String>、响应为List<String>
    @CryptoString(rule = PhoneCryptoRule.class)
    List<String> selectByPhones(List<String> phoneS);

    // 入参为单个List<String>、响应为List<String>
    @CryptoString(rule = PhoneCryptoRule.class)
    String[] selectByPhoneArr(String[] phoneS);

    // 入参为单个String且没有@Param注解、响应为String
    @CryptoString(rule = PhoneCryptoRule.class)
    String selectPhoneByPhone(String phone);

    @CryptoKey(key = "phone", rule = PhoneCryptoRule.class, mode = CryptoMode.DECRYPT)
    List<Map<String, Object>> selectByList(List<User> users);

    // 入参为多种情况下的示例
    List<User> selectByUserParam(UserParam param);

}
